<?php

include_once 'Expression.php';
include_once 'Statement.php';

/**
 * Represents a statement that throws an exception.
 * 
 * @package UC_PHPCodeModel
 * @author Uros Calakovic
 * @example ../Examples/ThrowStatementExample.php 
 */

class ThrowStatement extends Statement
{
    /**
     * The ThrowStatement constructor
     * @param ObjectCreateExpression $ToThrow The Exception instance to throw
     */
    
    public function __construct(ObjectCreateExpression $ToThrow = null)
    {
        parent::__construct();
        
        is_null($ToThrow) ?
            $this->ToThrow = new ObjectCreateExpression(new TypeReference('Exception')) :
            $this->set_ToThrow($ToThrow);
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @param mixed $value The value the field should be set to, usually a collection.
     * @see CodeObject::__set()
     */
    
    public function __set($name, $value)
    {
        parent::__set($name, $value);
        
        if($name == 'ToThrow')
        {
            $this->set_ToThrow($value);
        }
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @return mixed The field that $name specified, usually a collection
     * @see CodeObject::__get()
     */
    
    public function __get($name)
    {
        $ret = parent::__get($name);
        
        if($ret != null)
        {
            return $ret;
        }
        
        if($name == 'ToThrow')
        {
            return $this->get_ToThrow();
        }
    }
    
    /**
     * The $ToThrow getter method
     * @return ObjectCreateExpression 
     */
    
    public function get_ToThrow()
    {
        return $this->ToThrow;
    }

    /**
     * The $ToThrow setter method
     * @param ObjectCreateExpression $ToThrow 
     * 
     * @assert (123) throws PHPUnit_Framework_Error
     * @assert ('name') throws PHPUnit_Framework_Error
     * @assert (new stdClass()) throws PHPUnit_Framework_Error
     */
    
    public function set_ToThrow(ObjectCreateExpression $ToThrow)
    {
        $this->ToThrow = $ToThrow;
    }

    /**
     * The Exception instance to throw
     * @var ObjectCreateExpression 
     */
    
    private $ToThrow;
}

?>
